#include "SpotLightParser.h"

SpotLightParser::SpotLightParser(void)
{
}

SpotLightParser::~SpotLightParser(void)
{
}

SpotLightParser::SpotLightParser(string id, int light_id, int enabled, float angle, float exponent):
	LightParser(id,light_id,enabled)
{
	float pi=atan(1.0) * 4.0;
	this->angle = angle;
	this->exponent = exponent;
}

void SpotLightParser::setLight(){
	direction[0] = target[0] - location[0];
	direction[1] = target[1] - location[1];
	direction[2] = target[2] - location[2];

	float d = sqrt(direction[0]*direction[0] + direction[1]*direction[1] + direction[2]*direction[2]);
	direction[0] /= d;
	direction[1] /= d;
	direction[2] /= d;

	glLightfv(light_i, GL_AMBIENT, ambient);
	glLightfv(light_i, GL_DIFFUSE, diffuse);
	glLightfv(light_i, GL_SPECULAR, specular);

	glLightf(light_i, GL_CONSTANT_ATTENUATION, 0);
	glLightf(light_i, GL_LINEAR_ATTENUATION,1);
	glLightf(light_i, GL_QUADRATIC_ATTENUATION, 0);

	if(enabled)
		glEnable(light_i);
}

void SpotLightParser::setLightPos(){
	glLightf(light_i, GL_SPOT_CUTOFF, angle);
	glLightf(light_i, GL_SPOT_EXPONENT, exponent);
	glLightfv(light_i, GL_SPOT_DIRECTION, direction);
	glLightfv(light_i, GL_POSITION,location);
}